import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:张熳
 * Date:2025-09-08
 * Time:21:22
 */
public class Test {
    public static int countSegments(String s) {
        int len = s.length();
        if (len == 0) {
            return 0;
        }
        String[] ss = s.split(" ");
        int count = 0;
        for (String s1: ss) {
            if (s1.length() != 0) {
                count++;
            }
        }
        return count;
    }
    public static void main(String[] args) {
        //字符串中的单词数
        int ret = countSegments(", , , ,     a, cdef");
        System.out.println(ret);
    }
    public static String toLowerCase(String s) {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            //判断当前字符是不是字母
            if (Character.isLetter(ch)) {
                //判断是不是大写字母
                if (Character.isUpperCase(ch)) {
                    ch = (char)(ch + 32);//小写字母的ASCII码值比大写字母大32，想转换成小写就得加32并将其强转为char
                }
            }
            stringBuilder.append(ch);
        }
        return stringBuilder.toString();
    }
    public static void main5(String[] args) {
        //转换成小写字母
        String s = "HEllO wOrlD";
        System.out.println(toLowerCase(s));
    }
    String str = new String("good");
    char[] ch = {'a','b','c'};
    public void change(String str,char[] ch) {
        str = "world";//修改的是字符串的引用对象
        ch[0] = 'g';//修改的是字符数组中的内容
    }
    public static void main4(String[] args) {
        Test test = new Test();
        test.change(test.str,test.ch);
        System.out.print(test.str + " and ");
        System.out.println(test.ch);
    }
    public static boolean isPalindrome(String s) {
        s = s.toLowerCase();
        int left = 0;
        int right = s.length()-1;
        while (left < right) {
            while (left < right && !isNumberAndCharacter(s.charAt(left))) {
                left++;
            }
            while (left < right && !isNumberAndCharacter(s.charAt(right))) {
                right--;
            }
            if (s.charAt(left) == s.charAt(right)) {
                left++;
                right--;
            }else {
                return false;
            }
        }
        return true;
    }
    public static boolean isNumberAndCharacter(char ch) {
        if (Character.isDigit(ch) || Character.isLetter(ch)) {
            return true;
        }
        return false;
    }
    public static void main3(String[] args) {
        //检测字符串是否为回文串
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        boolean ret = isPalindrome(s);
        System.out.println(ret);
    }
    public static void main2(String[] args) {
        //最后一个单词的长度
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();

        //1.字符串拆分 split()
        String[] s = str.split(" ");
        int len = s[s.length-1].length();
        System.out.println(len);
        //2.找到最后一个空格的下标，然后截取空格后的字符串，然后求长度 lastIndexOf()  sunString()
        int index = str.lastIndexOf(" ");
        /*String ret = str.substring(index+1);
        System.out.println(ret.length());*/
        int ret = str.substring(index+1).length();
        System.out.println(ret);
    }
    public static int firstUniqChar(String s) {
        int[] count = new int[26];
        //统计每个字符出现的次数
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            count[ch-'a']++;
        }
        //找第一个只出现一次的字符
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (count[ch-'a'] == 1) {
                return i;
            }
        }
        return -1;
    }
    public static void main1(String[] args) {
        //第一个只出现一次的字符
        String s = "aabcc";
        int ret = firstUniqChar(s);
        System.out.println(ret);
    }
}
